< previous page page_664 next page >

Page 664
analysis.gifRemember that the Source argument is a reference to the image control being dropping on the list box. Therefore, the Tag property you set in the image control is used as the parameter to the AddItem method of the list box when the control is dropped. You should always use the TypeOf operator to make sure the user is attempting to drop the appropriate type of control. For example, if you had a label control on the form as well as the image controls, you might not get a valid Tag property to load into the list box.

Removing Items from the List Box
Youve seen how to add items to the list box. Lets now look at how to take items out of the list box. In this case, you set one icon on the list box for the drag operation. However, when the user drags the list box over the appropriate image control, you want to signify to the user that this is the image control that he or she can drop it on. This is accomplished by changing the DragIcon property when the user is over the appropriate image control.
EXERCISE
Loading the DragIcon at Runtime
1. Set the DragIcon property of the list box to the Folder05.ico file located in the examples folder for this chapter.
2. Make sure the DragMode property of the list box is set to 0 - Manual.
3. Double-click the list box.
4. Select the MouseDown event from the Procedures combo box.
5. Add the following code to the MouseDown event:
Private Sub lstThings_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
lstThings.DragIcon = _
LoadPicture("folder05.ico")
lstThings.Drag vbBeginDrag
End Sub
analysis.gifIn the MouseDown event, you need to reset the DragIcon property so that you dont need to reset it when the user drops the item on the appropriate ImageList control. This just saves a little code in each DragDrop event

 
< previous page page_664 next page >

If you like this book, buy it!